<?php
namespace Orm\PlaySettings;

use Base\Exception\RmException;
class PlaySettingsClass extends \Base\BaseOrmObject{
    protected   $id,
				$type = 0, // 1，胜平负；2，半全场；3，比分
				$title = '', // 预猜标题
				$score_a = 0, // 竞猜A队进球
				$score_b = 0, // 竞猜B队进球
                $sort = 0, //排序
				$is_del = 0,
				$insert_time = '',
				$update_time = '';

    function __init($data)
    {
        parent::__init($data);
        $this->dformat($data);
    }

    private function dformat()
    {
    }

    public function loadById($id = 0)
    {
        $model = new \Orm\PlaySettings\PlaySettingsModel();
        $data = $model->loadById($id);
        self::__init($data);
    }

    public function insert()
    {
        $this->checkNecessaryParam();
        $data = array(
            'type' => $this->type,
			'title' => $this->title,
			'score_a' => $this->score_a,
			'score_b' => $this->score_b,
            'sort' => $this->sort,
        );

        $model = new \Orm\PlaySettings\PlaySettingsModel();
        $model->insert($data);
        $this->id = $model->getLastId();
    }

    public function update()
    {
        $this->checkNecessaryParam();
        $data = array(
            'type' => $this->type,
			'title' => $this->title,
			'score_a' => $this->score_a,
			'score_b' => $this->score_b,
            'sort' => $this->sort,
        );

        $model = new \Orm\PlaySettings\PlaySettingsModel();
        $is_update = $model->update($data, "`id` = {$this->id}");
        return $is_update;
    }

    public function delete($id)
    {
        $data = array('is_del'=>1);
        $model = new \Orm\PlaySettings\PlaySettingsModel();
        $model->update($data, "`id` = {$id}");
    }

    private function checkNecessaryParam()
    {
    }
}